package com.fingard.dsp.bank.directbank.spdb01.authforrec;

import sun.misc.BASE64Encoder;

import java.util.HashMap;
import java.util.Map;


/**
 * 跨行
 *
 * @author T-chenqy
 */
public class BankTrans {
    /**
     * 转16进制字符串发送
     *
     * @param data       明文数据
     * @param sessionKey 会话密钥
     * @param timeStr    时间戳
     * @param corpNo
     * @return
     * @throws Exception
     */
    public static String encryptStr(String data, String sessionKey, String timeStr, String corpNo) throws Exception {
        String xml = StringUtils.bytesToHexString(SecurityAES.encrypt(data, sessionKey));
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("ReqTime", timeStr);
        param.put("ReqData", xml);
        param.put("CorpNo", corpNo);
        return XMLFillValueHelper.getInstance().buildXML("package.xml", param);
    }

    /**
     * 转16进制字符串发送
     *
     * @param data       明文数据
     * @param sessionKey 会话密钥
     * @param timeStr    时间戳
     * @param corpNo
     * @return
     * @throws Exception
     */
    public static String encryptStrBASE64(String data, String sessionKey, String timeStr, String corpNo)
            throws Exception {
        String xml = new BASE64Encoder().encode(SecurityAES.encryptBASE64(data, sessionKey));
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("ReqTime", timeStr);
        param.put("ReqData", xml);
        param.put("CorpNo", corpNo);
        return XMLFillValueHelper.getInstance().buildXML("package.xml", param);
    }
}
